package com.ruoyi.project.equipment.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.equipment.domain.Product;
import com.ruoyi.project.equipment.service.ProductService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 存储产品属性的数据库Controller
 *
 * @author ruoyi
 * @date 2020-07-02
 */
@RestController
@RequestMapping("/equipment/product")
public class ProductController extends BaseController
{
    @Autowired
    private ProductService productService;

    /**
     * 查询存储产品属性的数据库列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(Product product)
    {
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);
    }

    /**
     * 导出存储产品属性的数据库列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:export')")
    @Log(title = "存储产品属性的数据库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Product product)
    {
        List<Product> list = productService.selectProductList(product);
        ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 获取存储产品属性的数据库详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:query')")
    @GetMapping(value = "/{pId}")
    public AjaxResult getInfo(@PathVariable("pId") Integer pId)
    {
        return AjaxResult.success(productService.selectProductById(pId));
    }

    /**
     * 新增存储产品属性的数据库
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:add')")
    @Log(title = "存储产品属性的数据库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Product product)
    {
        return toAjax(productService.insertProduct(product));
    }

    /**
     * 修改存储产品属性的数据库
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:edit')")
    @Log(title = "存储产品属性的数据库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Product product)
    {
        return toAjax(productService.updateProduct(product));
    }

    /**
     * 删除存储产品属性的数据库
     */
    @PreAuthorize("@ss.hasPermi('equipment:product:remove')")
    @Log(title = "存储产品属性的数据库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pIds}")
    public AjaxResult remove(@PathVariable Integer[] pIds)
    {
        return toAjax(productService.deleteProductByIds(pIds));
    }
}